home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / ARTAbrot 1.21 / About_ARTAbrot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-08  |  6.8 KB  |  185 lines  |  [TEXT/MPS ]

  1. /* About_ARTAbrot */
  2.  
  3. /* File name: About_ARTAbrot */
  4. /* Function: Handle a modeless dialog */
  5. /*            This dialog operates like a window, it is not modal. */
  6. /*           Opened by:    */
  7. /*           Closed by:     */
  8. /*           Purpose:       
  9. History: 8/18/93 Original by George Warner */
  10.  
  11.  
  12. #include "ComUtil_ARTAbrot.h"    /* Common */
  13. #include "AB_Alert.h"    /* Alert */
  14. #include "About_ARTAbrot.h"    /* This modeless dialog */
  15.  
  16. #pragma segment About_ARTAbrot
  17.  
  18. /* ======================================================= */
  19.  
  20.  
  21. /* ======================================================= */
  22.  
  23. /* Routine: Init_About_ARTAbrot */
  24. /* Purpose: This procedures purpose is to set the window pointer to nil, */
  25. /* this is used to tell the other routines */
  26.  
  27. void Init_About_ARTAbrot()
  28. {
  29.     WPtr_About_ARTAbrot = NIL;    /* Initialize to say that the dialog is not yet active */
  30. }
  31.  
  32. /* ======================================================= */
  33.  
  34. /* Routine: Moved_About_ARTAbrot */
  35. /* Purpose: We were moved, possibly to another screen and screen depth */
  36.  
  37. void Moved_About_ARTAbrot(WindowPtr theWindow)/* Moved this window */
  38. {
  39. WindowPtr    SavePort;                        /* Place to save the last port */
  40.  
  41.     if (WPtr_About_ARTAbrot == theWindow) {    /* Only do if the window is us */
  42.         GetPort(&SavePort);                    /* Save the current port */
  43.         SetPort(theWindow);                    /* Set the port to my window */
  44.  
  45.         SetPort(SavePort);                    /* Restore the old port */
  46.     }
  47. }
  48.  
  49. /* ======================================================= */
  50.  
  51. /* Routine: Update_About_ARTAbrot */
  52. /* Purpose: This procedures purpose is to refresh this window, update it, */
  53. /* when we are uncovered by another window.  */
  54.  
  55. void Update_About_ARTAbrot(WindowPtr theWindow)
  56. {
  57. GrafPtr    SavedPort;                            /* Save the current port so we can restore to it */
  58. Rect    rTempRect, tempRect;                /* Temporary rectangle variable */
  59. RGBColor    Saved_ForeColor;                /* Place to save colors */
  60. RGBColor    Saved_BackColor;                /* Place to save colors */
  61. RGBColor    DrawingColor;                    /* Place to make colors */
  62. PicHandle    Pic_Handle;                            /* Handle used in displaying pictures */
  63.  
  64.     /* Only do if we are the window to update */
  65.     if ((WPtr_About_ARTAbrot != nil) && (theWindow == WPtr_About_ARTAbrot)) {
  66.         GetPort(&SavedPort);                /* Get the current port */
  67.         SetPort(theWindow);                    /* Point to our port for drawing in our window */
  68.  
  69.         GetForeColor(&Saved_ForeColor);        /* Save the fore color */
  70.         GetBackColor(&Saved_BackColor);        /* Save the back color */
  71.  
  72.         DrawingColor.red = 0xFFFF;  DrawingColor.green = 0xFFFF;  DrawingColor.blue = 0x0;/* Set the color */
  73.         RGBForeColor(&DrawingColor);        /* Set the fore color */
  74.  
  75.         Pic_Handle = GetPicture(Pict_Picture);    /* Get Picture into memory */
  76.         SetRect(&tempRect, 0,0,300,180);        /* left,top,right,bottom */
  77.         if (Pic_Handle != nil) {                 /* Only use handle if it is valid */
  78.             DrawPicture(Pic_Handle, &tempRect);    /* Draw this picture */
  79.         }
  80.  
  81.         /* Display the status lines. */
  82.         TextFont(geneva);                        /* Select the Font that we want */
  83.         TextSize(9);
  84.         /* Draw a string of text. */
  85.         MoveTo(95, 80);
  86.         DrawString("\pARTAbrot Version 1.21");
  87.         MoveTo(95, 90);
  88.         DrawString("\pGeorge Warner");
  89.         MoveTo(95, 100);
  90.         DrawString("\p03/26/94");
  91.         MoveTo(95, 110);
  92.         DrawString("\pwarnergt@aloft.att.com");
  93.  
  94.         TextSize(12);
  95.         TextFont(systemFont);                /* Select the Font that we want */
  96.         TextFace(0);                        /* Select the style that we want */
  97.  
  98.         RGBForeColor(&Saved_ForeColor);        /* Restore the fore color */
  99.         RGBBackColor(&Saved_BackColor);        /* Restore the back color */
  100.  
  101.         DrawDialog(theWindow);                /* Draw the rest of the controls */
  102.         SetPort(SavedPort);                    /* Restore the port that we saved at the start */
  103.     }
  104. }
  105.  
  106. /* ======================================================= */
  107.  
  108. /* Routine: Open_About_ARTAbrot */
  109. /* Purpose: This procedures purpose is to open this window and set all */
  110. /* of the initial conditions, such as default edit text. */
  111.  
  112. void Open_About_ARTAbrot()
  113. {
  114. Rect    tempRect;                                /* Temporary rectangle */
  115. int top, left;
  116.  
  117.     if (WPtr_About_ARTAbrot == NIL) {
  118.         WPtr_About_ARTAbrot = GetNewDialog(Res_MD_About_ARTAbrot, NIL,  (WindowPtr)-1 );/* Bring in the dialog resource */
  119.  
  120.         /* Get window size, we will now center it */
  121.         tempRect.top = WPtr_About_ARTAbrot->portRect.top;
  122.         tempRect.left = WPtr_About_ARTAbrot->portRect.left;
  123.         tempRect.bottom = WPtr_About_ARTAbrot->portRect.bottom;
  124.         tempRect.right = WPtr_About_ARTAbrot->portRect.right;
  125.         top = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;/* Center vert */
  126.         left = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;/* Center Horz */
  127.         /* Now move the window to the proper position */
  128.         MoveWindow(WPtr_About_ARTAbrot, left, top, true);
  129.  
  130.         SetPort(WPtr_About_ARTAbrot);        /* Prepare to add conditional text */
  131.         Doing_MovableModal = true;            /* We are now in the movable modal mode */
  132.  
  133.         ShowWindow(WPtr_About_ARTAbrot);    /* Open a dialog box */
  134.         SelectWindow(WPtr_About_ARTAbrot);    /* Lets see it */
  135.     }
  136.     else
  137.         SelectWindow(WPtr_About_ARTAbrot);    /* Lets see it */
  138. }
  139.  
  140. /* ======================================================= */
  141.  
  142. /* Routine: Close_About_ARTAbrot */
  143. /* Purpose: This procedures purpose is to close this window and clear */
  144. /* the window pointer variable */
  145.  
  146. void Close_About_ARTAbrot(WindowPtr theWindow)
  147. {
  148.     /* Only close if it is us and we were open */
  149.     if ((WPtr_About_ARTAbrot != NIL) && (theWindow == WPtr_About_ARTAbrot)) {
  150.         Doing_MovableModal = false;        /* We are now out of the movable modal mode */
  151.         DisposDialog(theWindow);        /* Close on the screen and Flush the dialog out of memory */
  152.         WPtr_About_ARTAbrot = nil;        /* Make sure our other routines know that we are closed */
  153.     }
  154. }
  155.  
  156. /* ======================================================= */
  157.  
  158.  
  159. /* Routine: Do_About_ARTAbrot */
  160. /* Purpose: This procedures purpose is to handle all actions, such as buttons being pressed. */
  161. /* This is the real meat of this unit and is where the code is for acting upon the users actions. */
  162.  
  163. void Do_About_ARTAbrot(EventRecord *theEvent,WindowPtr theWindow,short itemHit)
  164. {
  165. Point    myPt;                                /* For the local mouse position */
  166. short    DType;                                /* Type of dialog item */
  167. Handle    DItem;                                /* Handle to the dialog item */
  168. Rect    tempRect;                            /* Temporary rectangle */
  169. ControlHandle    CItem;                        /* Control handle */
  170.  
  171.     if ((theEvent->what == mouseDown) && (WPtr_About_ARTAbrot != nil)) {
  172.         SetPort(WPtr_About_ARTAbrot);        /* Set the port to our dialog */
  173.         myPt = theEvent->where;                /* Get the position where the mouse was pressed */
  174.         GlobalToLocal(&myPt);                /* Change from global to local location */
  175.     }
  176.  
  177.     if ((WPtr_About_ARTAbrot != nil)  && (WPtr_About_ARTAbrot  == theWindow)) {
  178.         if ((theEvent->what == keyDown) || (theEvent->what == mouseDown)) {
  179.             /* Close the window when a key is hit or mouse button is pressed. */
  180.             Add_UserEvent(UserEvent_Close_Window,Res_MD_About_ARTAbrot,0,0,nil);
  181.             Play_The_Sound(Snd_Bart__Cooool);    /* Play my sound */
  182.         }
  183.     }
  184. }
  185.